package com.free.ip.vo;

import com.free.ip.util.Constants;

/**
 * 用来封装ip相关信息，目前只有三个字段，ip地址、所在的国家和地区
 * 
 * @author YongXia.
 * 
 * @since jdk1.6
 * @version 1.0
 * 
 */
public class IPLocation {
    private String area;
    private String country;
    private String ip;

    public IPLocation() {
        super();
    }

    public IPLocation(final String ip, final String country, final String area) {
        this.ip = ip;
        this.country = country;
        this.area = area;
    }

    public String getArea() {
        return this.area;
    }

    /**
     * 复制一个IPLocation对象。
     * 
     * @return 此对象的复制对象.
     */
    public IPLocation getCopy() {
        return new IPLocation(this.ip, this.country, this.area);
    }

    public String getCountry() {
        return this.country;
    }

    public final String getIp() {
        return this.ip;
    }

    public void setArea(final String area) {
        // 如果为局域网，纯真IP地址库的地区会显示CZ88.NET,这里把它去掉
        if (Constants.CZ88_DOT_NET.equalsIgnoreCase(area.trim())) {
            this.area = Constants.MSG_LOCALHOST_OR_LAN;
        } else {
            this.area = area;
        }
    }

    public void setCountry(final String country) {
        this.country = country;
    }

    public final void setIp(final String ip) {
        this.ip = ip;
    }

    @Override
    public String toString() {
        return new StringBuffer().append("IP:").append(this.ip).append(", Country:").append(this.country)
                .append(", Area:").append(this.area).toString();
    }
}
